﻿using System;
using GeoAPI.Geometries;
using NetTopologySuite.Noding;

namespace NetTopologySuite.Geometries.Prepared
{
	public class PreparedLineString : BasicPreparedGeometry
	{
		public PreparedLineString(ILineal line) : base((IGeometry)line)
		{
		}

		public FastSegmentSetIntersectionFinder IntersectionFinder
		{
			get
			{
				if (this._segIntFinder == null)
				{
					object @lock = this._lock;
					lock (@lock)
					{
						if (this._segIntFinder == null)
						{
							this._segIntFinder = new FastSegmentSetIntersectionFinder(SegmentStringUtil.ExtractSegmentStrings(base.Geometry));
						}
					}
				}
				return this._segIntFinder;
			}
		}

		public override bool Intersects(IGeometry g)
		{
			return base.EnvelopesIntersect(g) && PreparedLineStringIntersects.Intersects(this, g);
		}

		private readonly object _lock = new object();

		private volatile FastSegmentSetIntersectionFinder _segIntFinder;
	}
}
